import { AdColumn, useAdRender } from '@/components/AdTable';
import { ref, h } from 'vue';
import { TreeItem } from '@/components/Tree/index';
import { AjaxResult } from '@/api/model';
import type { DescItem } from '@/components/Description/index';
import { GetMaterialTreeNodes, GetDictNodes } from './ipn.api';
import { List } from '@/components/Linqts';
import { forEach } from '@/utils/helper/treeHelper';
import { getStatusSchema } from './ipn.enum';
import { isBoolean, isString, isNumber, isArray, isFunction, isObject } from '@/utils/is';
import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { Tag } from 'ant-design-vue';

const statusEnumSchema = getStatusSchema();
const materials: List<any> = new List();
const toMaterialArray = function (data) {
  if (isArray(data) && (data as Array<any>).length > 0) {
    new List(data).ForEach((i) => {
      materials.Add(i);
      //@ts-ignore
      toMaterialArray(i.Children);
    });
  }
  return;
};

export const columns: AdColumn[] = [
  {
    title: '主键',
    dataIndex: 'Id',
    dataType: 'guid',
    width: 300,
    defaultHidden: true,
    filterable: false,
    sorter: true,
    formVisible: false,
    formEditable: false,
  },
  {
    title: 'IPN号',
    dataIndex: 'IpnNo',
    dataType: 'text',
    width: 150,
    defaultHidden: false,
    filterable: true,
    sorter: true,
    formVisible: true,
    formEditable: true,
    formSchema: {
      colProps: {
        offset: 3,
        // span: 24,
        xs: 16, // <576px
        sm: 16, // ≥576px
        md: 16, // ≥768px
        lg: 16, // ≥992px
        xl: 16, // ≥1200px
        xxl: 16, // ≥1600px
        // xxxl: 24, // ≥2000px 3.0
      },
    },
  },
  // {
  //   title: '状态',
  //   dataIndex: 'Status',
  //   dataType: 'enum',
  //   width: 150,
  //   filterable: true,
  //   sorter: true,
  //   enumData: statusEnumSchema,
  //   formVisible: true,
  //   formEditable: false,
  //   formSchema: {
  //     colProps: {
  //       offset: 3,
  //       // span: 24,
  //       xs: 16, // <576px
  //       sm: 16, // ≥576px
  //       md: 16, // ≥768px
  //       lg: 16, // ≥992px
  //       xl: 16, // ≥1200px
  //       xxl: 16, // ≥1600px
  //       // xxxl: 24, // ≥2000px 3.0
  //     },
  //   },
  // },
  {
    title: '类别名称',
    dataIndex: 'MaterialCategoryName',
    width: 100,
    defaultHidden: false,
    filterable: false,
    formVisible: false,
    formEditable: false,
  },
  {
    title: '物料分类',
    dataIndex: 'MaterialCategoryId',
    dataType: 'guid',
    width: 150,
    formVisible: false,
    formEditable: false,
    required: true,
    defaultHidden: true,
    filterable: false,
    sorter: false,
    editComponent: 'ApiTreeSelect',
    editComponentProps: {
      api: GetMaterialTreeNodes,
      resultField: 'Data',
      labelField: 'Name',
      valueField: 'Id',
      childrenField: 'Children',
      treeNodeFilterProp: 'Name',
      onChange: (e) => {
        console.log('selected:', e);
      },
    },
    formSchema: {
      colProps: {
        // span: 24,
        xs: 24, // <576px
        sm: 24, // ≥576px
        md: 24, // ≥768px
        lg: 24, // ≥992px
        xl: 24, // ≥1200px
        xxl: 24, // ≥1600px
        // xxxl: 24, // ≥2000px 3.0
      },
    },
  },
  {
    title: '部件名称',
    dataIndex: 'Name',
    dataType: 'string',
    width: 150,
    required: true,
    filterable: true,
    sorter: true,
    formVisible: false,
    formEditable: false,
  },
  {
    title: '单位',
    dataIndex: 'Unit',
    dataType: 'integer',
    width: 150,
    defaultHidden: true,
    formVisible: false,
    formEditable: false,
    required: true,
    filterable: true,
    sorter: true,
    editComponent: 'ApiSelect',
    editComponentProps: {
      api: GetDictNodes,
      params: 'unit',
      resultField: 'Data',
      // use name as label
      labelField: 'CodeName',
      // use id as value
      valueField: 'CodeValue',
      immediate: true,
      optionFilterProp: 'label',
      showSearch: true,
    },
  },
  {
    title: '规格型号/描述',
    dataIndex: 'Description',
    dataType: 'text',
    width: 150,
    formVisible: false,
    formEditable: false,
    required: false,
    filterable: false,
    sorter: false,
    formSchema: {
      colProps: {
        // span: 24,
        xs: 24, // <576px
        sm: 24, // ≥576px
        md: 24, // ≥768px
        lg: 24, // ≥992px
        xl: 24, // ≥1200px
        xxl: 24, // ≥1600px
        // xxxl: 24, // ≥2000px 3.0
      },
    },
  },
  {
    title: '生产商',
    dataIndex: 'Manufacturer',
    dataType: 'string',
    width: 150,
    formVisible: false,
    formEditable: false,
    required: false,
    filterable: false,
    sorter: false,
    formSchema: {
      colProps: {
        // span: 24,
        xs: 24, // <576px
        sm: 24, // ≥576px
        md: 24, // ≥768px
        lg: 24, // ≥992px
        xl: 24, // ≥1200px
        xxl: 24, // ≥1600px
        // xxxl: 24, // ≥2000px 3.0
      },
    },
  },
  {
    title: '存货属性',
    dataIndex: 'StockAttributes',
    dataType: 'string',
    width: 150,
    formVisible: false,
    formEditable: false,
    required: true,
    filterable: false,
    sorter: false,
  },
  {
    title: '所属项目',
    dataIndex: 'Project',
    dataType: 'integer',
    width: 150,
    defaultHidden: true,
    formVisible: false,
    formEditable: false,
    required: true,
    filterable: true,
    sorter: true,
    editComponent: 'ApiSelect',
    editComponentProps: {
      api: GetDictNodes,
      params: 'project',
      resultField: 'Data',
      // use name as label
      labelField: 'CodeName',
      // use id as value
      valueField: 'CodeValue',
      immediate: true,
      optionFilterProp: 'label',
      showSearch: true,
    },
  },
  {
    title: '备注',
    dataIndex: 'Remark',
    dataType: 'text',
    width: 150,
    formVisible: false,
    formEditable: false,
    required: false,
    filterable: false,
    sorter: false,
    formSchema: {
      colProps: {
        // span: 24,
        xs: 24, // <576px
        sm: 24, // ≥576px
        md: 24, // ≥768px
        lg: 24, // ≥992px
        xl: 24, // ≥1200px
        xxl: 24, // ≥1600px
        // xxxl: 24, // ≥2000px 3.0
      },
    },
  },
  {
    title: '创建时间',
    dataIndex: 'CreatedTime',
    dataType: 'datetime',
    width: 200,
    formVisible: true,
    formEditable: false,
    required: false,
    filterable: false,
    sorter: true,
    formSchema: {
      colProps: {
        offset: 3,
        // span: 24,
        xs: 16, // <576px
        sm: 16, // ≥576px
        md: 16, // ≥768px
        lg: 16, // ≥992px
        xl: 16, // ≥1200px
        xxl: 16, // ≥1600px
        // xxxl: 24, // ≥2000px 3.0
      },
    },
  },
];

export interface InputDto {}

export interface OutputDto {}
